// pages/my_apply/index.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        openid: '',
        user_data: '',
        apply_data: ''
    },
    onShow() {

        // 获取openID
        this.data.openid = getApp().globalData.openid;
        const db = wx.cloud.database();
        // 获取用户信息
        db.collection('user').get({openid: this.data.openid}).then(res =>{
            this.setData({
                user_data: res.data[0]
            })
        });
        // 调用applys数据获取函数
        this.getApplyData()
    },
    getApplyData() {
        const db = wx.cloud.database();
        // 查询申请单并按照时间排序
        db.collection('applys').orderBy('state', 'asc').orderBy('create_time', 'desc').get({applicant:this.data.user_data.name}).then(res =>{
            this.setData({
                apply_data: res.data
            })
            console.log(this.data.apply_data)
        })
    }
})